﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Entities.Services;
using Reviewer.Data;
using System.Web;
using Reviewer.Entities;
using System.Web.Caching;
using System.Collections.ObjectModel;

namespace Reviewer.Business.Services
{
    internal class FontPagePostService : BaseService, IFrontPagePostService, IFrontPagePostAdminService
    {
        internal FontPagePostService() : base() { }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #region IFrontPagePostService Members
        public ICollection<FrontPagePost> FindAll(int topCount)
        {
            if (topCount > 0)
            {
                return new FrontPagePostRepository().SelectAll(topCount);
            }
            else
            {
                return new FrontPagePostRepository().SelectAll();
            }
        }

        public FrontPagePost Find(int id)
        {
            return new FrontPagePostRepository().SelectBy(id);
        }

        public ICollection<FrontPagePost> Find(bool isActive, int maxResults)
        {
            return new FrontPagePostRepository().Select(isActive, maxResults);
        }

        #endregion

        #region IFrontPagePostAdminService Members

        public FrontPagePost Save(FrontPagePost post)
        {
            if (post.Id <= 0)
            {
                return new FrontPagePostRepository().Create(post);
            }
            else
            {
                return new FrontPagePostRepository().Update(post);
            }
        }

        public void Delete(int id)
        {
            new FrontPagePostRepository().Delete(id);
        }

        #endregion

    }
}
